#include "graph.h"
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>
const int N = 203;
using namespace std;
vector<int> mp[N];
vector<int> ret[N];
vector<int> key[N];
int cnt;
int ft[N], fe[N], d[N];
void dfs(int u) {
    d[u] = NumberOfRoads();
    fe[u] = LastRoad();
    mp[u].resize(d[u]);
    key[u].resize(d[u]);
    ret[u].resize(d[u]);
    if (u)
        mp[u][fe[u] - 1] = ft[u];
    for (int i = 0; i < d[u]; ++i)
        if (i + 1 != fe[u]) {
            Move(i + 1, 2);
            int c = Color();
            key[u][i] = c;
            if (c > 1)
                Move(ret[u][i] = LastRoad(), c);
            else {
                mp[u][i] = cnt++;
                ft[mp[u][i]] = u;
                dfs(mp[u][i]);
                Move(fe[mp[u][i]], 3);
            }
        }
}
int w[N], pw;
void go(int u) {
    for (int i = 0; i < d[u]; ++i)
        if (key[u][i] == 2) {
            Move(i + 1, w[u]);
            int c = Color();
            mp[u][i] += (c - 1) * pw;
            Move(LastRoad(), c);
        } else if (key[u][i] == 1) {
            Move(i + 1, w[u]);
            go(mp[u][i]);
            Move(fe[mp[u][i]], w[mp[u][i]]);
        }
}
int res[N], dis[N];
queue<int> que;
void Inspect(int R) {
    cnt = 1, pw = 1, ft[0] = -1;
    dfs(0);
    while (cnt > pw) {
        for (int i = 0; i < cnt; ++i)
            w[i] = i / pw % 3 + 1;
        go(0), pw *= 3;
    }
    for (int u = 0; u < cnt; ++u)
        for (int i = 0; i < d[u]; ++i)
            if (key[u][i] == 2)
                mp[mp[u][i]][ret[u][i] - 1] = u;
    for (int rt = 0; rt < cnt; ++rt) {
        for (int i = 0; i < cnt; ++i)
            dis[i] = -1;
        dis[rt] = 0;
        que.emplace(rt);
        while (!que.empty()) {
            int u = que.front();
            que.pop();
            for (int v : mp[u])
                if (dis[v] < 0) {
                    dis[v] = dis[u] + 1;
                    que.emplace(v);
                }
        }
        for (int i = 0; i < cnt; ++i)
            ++res[dis[i]];
    }
    for (int i = 1; i <= R; ++i)
        Answer(i, res[i] >> 1);
}
